import library_management.book.BookList;
import library_management.user.AdminUser;
import library_management.user.NormalUser;
import library_management.user.User;

import java.security.spec.RSAOtherPrimeInfo;
import java.util.Scanner;

public class Test {
    public static User login(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userName=scanner.next();
        boolean temp=true;
        while(temp){
            System.out.println("请根据您的身份进行选择：1、普通用户 2、管理员");
            int choice = scanner.nextInt();
            if(choice == 1)
            {
                return new NormalUser(userName);
            }
            else if(choice == 2)
            {
                return new AdminUser(userName);
            }
            else
            {
                System.out.println("输入错误请重新输入！");
                System.out.println("=====================================");
                continue;
            }
        }
        return new NormalUser(userName);
    }

    public static void main(String[] args) {
        User user=login();
        BookList bookList=new BookList();
        while (true){
            int choice=user.menu();
            if(choice == -1)
            {
                System.out.println("=====================================");
                System.out.println("期待您的下次光临，拜拜~");
                return;
            }
            if(user instanceof NormalUser && (choice < 1 || choice > 4)){
                System.out.println("用户输入错误！请从新输入：");
                continue;
            }
            else if(user instanceof AdminUser && (choice < 1 || choice > 5)){
                System.out.println("用户输入错误！请从新输入：");
                continue;
            }
            user.doOperation(choice,bookList);
        }
    }
}
